﻿using CodingWheels.DataTypes.Core;

namespace CodingWheels.DataTypes
{
	public class TimeUnit : Unit
	{
		public static readonly TimeUnit Nanoseconds = new TimeUnit("Nanoseconds", "nSecs");
		public static readonly TimeUnit Microseconds = new TimeUnit("Microseconds", "µSecs");
		public static readonly TimeUnit Milliseconds = new TimeUnit("Milliseconds", "mSecs");
		public static readonly TimeUnit Seconds = new TimeUnit("Seconds", "secs");
		public static readonly TimeUnit Minutes = new TimeUnit("Minutes", "mins");
		public static readonly TimeUnit Hours = new TimeUnit("Hours", "hrs");

		private TimeUnit(string name, string symbol) : base(name, symbol)
		{
		}
	}

	public class Time : DataType<Time, TimeUnit>
	{
		public Time() : base(0, TimeUnit.Nanoseconds)
		{
		}

		public Time(double value, TimeUnit unit) : base(value, unit)
		{
		}
	}

	internal class TimeConverter : Converter<TimeUnit>
	{
		public TimeConverter()
		{
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Nanoseconds, TimeUnit.Microseconds, 1000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Nanoseconds, TimeUnit.Milliseconds, 1000000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Nanoseconds, TimeUnit.Seconds, 1000000000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Nanoseconds, TimeUnit.Minutes, 60000000000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Nanoseconds, TimeUnit.Hours, 3600000000000));


			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Microseconds, TimeUnit.Milliseconds, 1000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Microseconds, TimeUnit.Seconds, 1000000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Microseconds, TimeUnit.Minutes, 60000000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Microseconds, TimeUnit.Hours, 3600000000));

			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Milliseconds, TimeUnit.Seconds, 1000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Milliseconds, TimeUnit.Minutes, 60000));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Milliseconds, TimeUnit.Hours, 3600000));

			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Seconds, TimeUnit.Minutes, 60));
			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Seconds, TimeUnit.Hours, 3600));

			AddConversion(Conversion<TimeUnit>.ConvertUsingDivision(TimeUnit.Minutes, TimeUnit.Hours, 60));
		}
	}
}
